package chapter07;
import java.util.concurrent.ArrayBlockingQueue;

public class java10_Collection_Queue {
    public static void main(String[] args) throws Exception {
        // TODO 集合 - Collection - Queue
        // ArrayBlockingQueue : Array + Blocking (阻塞 + 堵住) + Queue;
        ArrayBlockingQueue queue = new ArrayBlockingQueue<>(3);

//        queue.add("zhangsan");
//        queue.add("lisi");
//        queue.add("wangwu");
//        queue.add("zhaoliu"); ERROR : Queue full

//        queue.put("zhangsan");
//        queue.put("lisi");
//        queue.put("wangwu");
//        queue.put("zhaoliu");

        boolean zhangsan = queue.offer("zhangsan");
        System.out.println(zhangsan);
        boolean lisi = queue.offer("lisi");
        System.out.println(lisi);
        boolean wangwu = queue.offer("wangwu");
        System.out.println(wangwu);

//        System.out.println(queue.poll());
//        System.out.println(queue.poll());
//        System.out.println(queue.poll());
//        System.out.println(queue.poll());

        // 注意，take方法要在把异常抛出的时候才能用
        System.out.println(queue.take());
        System.out.println(queue.take());
        System.out.println(queue.take());
        System.out.println(queue.take());

        System.out.println(queue);
    }
}

